package com.sky.controller.user;

import com.sky.pojo.Setmeal;
import com.sky.result.Result;
import com.sky.service.user.UserSetMealService;
import com.sky.vo.DishItemVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user/setmeal")
public class UserSetMealController {
    @Autowired
    private UserSetMealService userSetMealService;

    @Cacheable(cacheNames = "setmealCache",key = "#categoryId") //key: setmealCache::100
    @GetMapping("/list")
    public Result<List<Setmeal>> findByCategoryId(Long categoryId){
        List<Setmeal> list = userSetMealService.findByCategoryId(categoryId);
        return Result.success(list);
    }

    @GetMapping("/dish/{setmealId}")
    public Result<List<DishItemVO>> findBySetMealId(@PathVariable Long setmealId){
        List<DishItemVO> list = userSetMealService.findBySetMealId(setmealId);
        return Result.success(list);
    }
}
